package com.pengcheng.taskapplication.mvp.view.activity;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.mvp.presenter.UserPresenterV2;
import com.pengcheng.taskapplication.net.IView;
import com.pengcheng.taskapplication.util.SPUtils;
import com.pengcheng.taskapplication.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class UpdateLimitMoney extends BaseActivity implements IView {

    @BindView(R.id.tv_center_title)
    TextView tv_center_title;

    @BindView(R.id.et_input_money)
    EditText et_input_money;
    UserPresenterV2 userPresenterV2;
    private String uid;
    private String newtoken;

    @Override
    protected int layoutResID() {
        return R.layout.activity_nopwd_limit;
    }

    @Override
    protected void initData() {
        tv_center_title.setText("免密金额修改");
        userPresenterV2 = new UserPresenterV2(this);
        uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        newtoken = SPUtils.getString(context, ConstantValue.SpType.newtoken);
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if(actionType.equals(ConstantValue.RequestKey.updateMoney)){
            //绑定成功，需要跳转
            ToastUtils.showShortToast("修改成功");
            this.finish();
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToast(msg);
    }

    @OnClick({R.id.img_back,R.id.ll_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.ll_next:
              String money=  et_input_money.getText().toString();
              if(money==null||money.length()==0){
                  ToastUtils.showShortToast("请输入免密金额");
                  return;
              }
                updateLimitMoney(newtoken,uid,Double.parseDouble(money));
                break;
        }
    }

    public void updateLimitMoney(String token,String uid,double money){
        userPresenterV2.updateLimitMoney(token,uid,money, ConstantValue.RequestKey.updateMoney);

    }
}
